<?php
/*********************/
/*                   */
/*  Version : 5.1.0  */
/*  Author  : RM     */
/*  Comment : 071223 */
/*                   */
/*********************/

if ( empty( $_GET['mod'] ) )
{
		$GLOBALS['_GET']['mod'] = "system";
}
define( "JIEQI_MODULE_NAME", $_GET['mod'] );
require_once( "../global.php" );
include_once( JIEQI_ROOT_PATH."/class/power.php" );
$power_handler =& jieqipowerhandler::getinstance( "JieqiPowerHandler" );
$power_handler->getsavedvars( $_GET['mod'] );
jieqi_checkpower( $jieqiPower[$_GET['mod']]['adminblock'], $jieqiUsersStatus, $jieqiUsersGroup, false, true );
jieqi_loadlang( "blocks", JIEQI_MODULE_NAME );
if ( empty( $_REQUEST['id'] ) )
{
		jieqi_printfail( $jieqiLang['system']['block_not_exists'] );
}
include_once( JIEQI_ROOT_PATH."/class/blocks.php" );
$blocks_handler =& jieqiblockshandler::getinstance( "JieqiBlocksHandler" );
$block = $blocks_handler->get( $_REQUEST['id'] );
if ( !is_object( $block ) )
{
		jieqi_printfail( $jieqiLang['system']['block_not_exists'] );
}
include_once( JIEQI_ROOT_PATH."/admin/header.php" );
include_once( JIEQI_ROOT_PATH."/class/modules.php" );
$modules_handler =& jieqimoduleshandler::getinstance( "JieqiModulesHandler" );
$criteria = new criteriacompo( new criteria( "publish", 1, "=" ) );
$criteria->setsort( "weight" );
$criteria->setorder( "ASC" );
$modules_handler->queryobjects( $criteria );
unset( $criteria );
$modules = array( );
while ( $v = $modules_handler->getobject( ) )
{
		$modules[$v->getvar( "name", "n" )] = $v->getvar( "caption", "n" );
}
$modules['system'] = LANG_MODULE_SYSTEM;
include_once( JIEQI_ROOT_PATH."/lib/html/formloader.php" );
if ( $block->getvar( "custom" ) == 1 )
{
		$blocks_form = new jieqithemeform( $jieqiLang['system']['edit_custom_block'], "blockedit", JIEQI_URL."/admin/blocks.php" );
		$blocks_form->addelement( new jieqiformtext( $jieqiLang['system']['table_blocks_blockname'], "blockname", 30, 50, $block->getvar( "blockname", "e" ) ), true );
		$modselect = new jieqiformselect( $jieqiLang['system']['table_blocks_modname'], "modname", $block->getvar( "modname", "e" ) );
		$modselect->addoptionarray( $modules );
		$blocks_form->addelement( $modselect );
}
else
{
		$blocks_form = new jieqithemeform( $jieqiLang['system']['edit_system_block'], "blockedit", JIEQI_URL."/admin/blocks.php" );
		$blockfile = $block->getvar( "filename" ).".php";
		$blocks_form->addelement( new jieqiformlabel( $jieqiLang['system']['table_blocks_filename'], $blockfile ) );
		if ( isset( $modules[$block->getvar( "modname" )] ) )
		{
				$blocks_form->addelement( new jieqiformlabel( $jieqiLang['system']['table_blocks_modname'], $modules[$block->getvar( "modname" )] ) );
		}
		else
		{
				$blocks_form->addelement( new jieqiformlabel( $jieqiLang['system']['table_blocks_modname'], LANG_UNKNOWN ) );
		}
		$blocks_form->addelement( new jieqiformtext( $jieqiLang['system']['table_blocks_blockname'], "blockname", 30, 50, $block->getvar( "blockname", "e" ) ), true );
}
$sideary = $blocks_handler->getsideary( );
$sideselect = new jieqiformselect( $jieqiLang['system']['table_blocks_side'], "side", $block->getvar( "side", "e" ) );
$sideselect->addoptionarray( $sideary );
$blocks_form->addelement( $sideselect );
$eleweight = new jieqiformtext( $jieqiLang['system']['table_blocks_weight'], "weight", 8, 8, $block->getvar( "weight", "e" ) );
$eleweight->setdescription( $jieqiLang['system']['note_block_weight'] );
$blocks_form->addelement( $eleweight );
$showradio = new jieqiformradio( $jieqiLang['system']['table_blocks_publish'], "publish", $block->getvar( "publish", "e" ) );
$showradio->addoption( 0, $jieqiLang['system']['block_show_no'] );
$showradio->addoption( 1, $jieqiLang['system']['block_show_logout'] );
$showradio->addoption( 2, $jieqiLang['system']['block_show_login'] );
$showradio->addoption( 3, $jieqiLang['system']['block_show_both'] );
$blocks_form->addelement( $showradio );
$blocks_form->addelement( new jieqiformtextarea( $jieqiLang['system']['table_blocks_title'], "title", $block->getvar( "title", "e" ), 3, 60 ) );
if ( $block->getvar( "custom" ) == 1 )
{
		$blocks_form->addelement( new jieqiformlabel( $jieqiLang['system']['table_blocks_contenttype'], "HTML" ) );
}
else
{
		$tmpary = $blocks_handler->getcontentary( );
		if ( isset( $tmpary[$block->getvar( "contenttype" )] ) )
		{
				$blocks_form->addelement( new jieqiformlabel( $jieqiLang['system']['table_blocks_contenttype'], $tmpary[$block->getvar( "contenttype" )] ) );
		}
		else
		{
				$blocks_form->addelement( new jieqiformlabel( $jieqiLang['system']['table_blocks_contenttype'], LANG_UNKNOWN ) );
		}
}
if ( $block->getvar( "canedit" ) == 1 )
{
		$blocks_form->addelement( new jieqiformtextarea( $jieqiLang['system']['table_blocks_content'], "content", $block->getvar( "content", "e" ), 10, 60 ) );
}
else
{
		$blockdesc = trim( $block->getvar( "description", "n" ) );
		if ( !empty( $blockdesc ) )
		{
				$blocks_form->addelement( new jieqiformlabel( $jieqiLang['system']['table_blocks_description'], $blockdesc ) );
		}
}
if ( $block->getvar( "hasvars" ) )
{
		$blocks_form->addelement( new jieqiformtextarea( $jieqiLang['system']['table_blocks_blockvars'], "blockvars", $block->getvar( "vars", "e" ), 3, 60 ) );
		$blocks_form->addelement( new jieqiformtext( $jieqiLang['system']['block_template_file'], "blocktemplate", 30, 50, $block->getvar( "template", "e" ) ) );
		$saveradio = new jieqiformradio( $jieqiLang['system']['block_save_type'], "savetype", 0 );
		$saveradio->addoptionarray( array(
				"0" => $jieqiLang['system']['block_save_self'],
				"1" => $jieqiLang['system']['block_save_another']
		) );
		$blocks_form->addelement( $saveradio );
		if ( $block->getvar( "hasvars" ) == 2 )
		{
				$blocks_form->addelement( new jieqiformhidden( "cacheupdate", "1" ) );
		}
}
$blocks_form->addelement( new jieqiformhidden( "action", "update" ) );
$blocks_form->addelement( new jieqiformhidden( "id", $block->getvar( "bid" ) ) );
$blocks_form->addelement( new jieqiformbutton( "&nbsp;", "submit", $jieqiLang['system']['save_block'], "submit" ) );
$jieqiTpl->assign( "jieqi_contents", "<br />".$blocks_form->render( JIEQI_FORM_MIDDLE )."<br />" );
include_once( JIEQI_ROOT_PATH."/admin/footer.php" );
?>
